import MessageHandler from "@runtime/module/Handler/MessageHandler";
import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import LabelComponent from "@runtime/UnityEngineBridge/LabelComponent";
import MenuIndexData from "@components/Apps/Simulation/menu/MenuIndex";

/**
 * 标签刷新消息
 */
export default class LabelUpdateMessageHandler extends MessageHandler<ClientMessage.LabelUpdateMessage> {
    protected async RunAsync(message: ClientMessage.LabelUpdateMessage): Promise<void> {
        // console.log(message.Informations, '刷新的信息+++++++');
        // MenuIndexData.Default.LabelDataList.value = message.Informations
        message.Informations.forEach(item => {
            MenuIndexData.Default.LabelDataList.value.forEach(j  => {
                if (item.InstanceId == j.InstanceId) {
                   j.ViewportPointX = item.ViewportPointX
                   j.ViewportPointY = item.ViewportPointY
                }
            });
            MenuIndexData.Default.OptionLabel.value.forEach(j  => {
                if (item.InstanceId == j.InstanceId) {
                   j.ViewportPointX = item.ViewportPointX
                   j.ViewportPointY = item.ViewportPointY
                }
            });

        });
        for (const information of message.Informations) {
            LabelComponent.Default.Update(information);
        }
    }
}
